package com.cloud.client;

import okhttp3.CacheControl;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
 * NextGis那边没带缓存头，自己拦截一下缓存
 *
 */
public class NetCacheInterceptor implements Interceptor {
    @NotNull
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        Response originResponse = chain.proceed(request);
        CacheControl cacheControl = new CacheControl.Builder()
                .maxAge(8, TimeUnit.MINUTES)
                .build();

        originResponse = originResponse.newBuilder()
                .removeHeader("pragma")
                .removeHeader("Cache-Control")
                .header("Cache-Control", cacheControl.toString())
                .build();
        return originResponse;
    }
}
